-
Notifications
You must be signed in to change notification settings - Fork 63
fix: update apidiff script to install tool and set up remote repository #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5856eae
to
c532ab2
Compare
/test pull-structured-merge-diff-apidiff |
c532ab2
to
a4d8c8a
Compare
a4d8c8a
to
647b6f4
Compare
/cc @jpbetz |
hack/apidiff.sh
Outdated
fi | ||
|
||
# Ensure the remote is set | ||
if ! git remote get-url origin &> /dev/null; then | ||
git remote add origin https://github.com/kubernetes-sigs/structured-merge-diff.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would an error be more appropriate? Modifying git configuration as a side effect makes me slightly uncomfortable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, same, the other problem is that origin is the default so it may be the user's fork.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we instruct people to use "upstream" (the original repo under kubernetes) and "origin" (your fork) as the remotes, but e can't guarantee it.
see also: the apidiff script in kubernetes/kubernetes
@BenTheElder Would you be willing to do a bash review? I'm not amazing at scripting. At a glance this looks like it does what we expect. I'm mostly curious if you know if better ways to do any of these things or if you see any hidden footguns. |
hack/apidiff.sh
Outdated
@@ -55,10 +55,21 @@ fi | |||
|
|||
# Check for apidiff tool, install it if not found | |||
if ! command -v "${API_DIFF_TOOL}" &> /dev/null; then | |||
GOBIN=${GOBIN:-$(go env GOPATH)/bin} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically it would be more polite to use a temporary local GOBIN instead of writing binaries to the system GOBIN
in kubernetes/kubernetes build outputs go under _output/
(which is gitignored) and we create a temp GOBIN under there.
the actual compile cache will be reused from the system but we'll avoid modifying binaries in the real user PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with a local GOBIN and output to _output/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like we also need .gitignore, https://github.com/kubernetes-sigs/structured-merge-diff/blob/master/.gitignore only has .idea
I guess being a library, we don't have a standard build output location yet for this repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be fine use delete the created directory after execution.
c5b6bfc
to
03d9441
Compare
/test pull-structured-merge-diff-apidiff |
03d9441
to
9050971
Compare
9050971
to
96b763a
Compare
hack/apidiff.sh
Outdated
mkdir -p "${LOCAL_GOBIN}" | ||
|
||
# Add cleanup trap to remove the temporary binary directory | ||
trap 'rm -rf "${LOCAL_GOBIN}"' EXIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could add this to a make clean
like target instead, if we add other things under _output/bin
in the future, this will race on deleting all of them?
We usually have an exit trap for e.g. a tmpdir that is scoped to the lifetime of the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I combined all into the cleanup function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that if we have any other scripts install tools, this script is clobbering the entire fixed gobin, instead we could probably just leave it behind and leave removing it to something like make clean
(manually invoked), or we should use a temp path that is specific to this script run. (like mktemp -d under _output)
BTW re: bash, when in doubt I highly recommend shellcheck.net, we use this in k/k with very few options set. (We do ignore a few of the lints, but not many). There are IDE plugins. |
41cf617
to
b9f7445
Compare
hack/apidiff.sh
Outdated
fi | ||
|
||
# Verify base commit exists | ||
REFERENCE_REVISION="$(git rev-parse --verify "${REFERENCE_REVISION}")" | ||
|
||
# Step 1: Create a temporary directory for worktrees | ||
TMP_DIR=$(mktemp -d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my suggestion: use the shared tempdir for work scoped to this script run..
create underneath this a gopath and a worktree subdir
use a shared exit trap to remove the whole thing.
you may want to create the tempdir under something like _output, for performance reasons if you're doing worktree etc (otherwise they may be on different filesystems), you can do this with an argument to mktemp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and gitignore _output (or similar), whatever paths we use within the repo that are for builds/intermediate outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, I updated to move things into the shared temp dir under _output
b9f7445
to
d3de6bc
Compare
/test pull-structured-merge-diff-apidiff |
I think this looks right, thanks! |
/approve Thanks @BenTheElder for reviewing this one! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jpbetz, yongruilin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
fix error when execute apidiff.sh
1.
ref: #276